package com.siemens.industrial.app;

import org.quartz.*;

import java.io.IOException;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Created by weig on 8/23/16.
 */
public class MainApplication {
    public static void main(String[] arg) {
        try {
            Scheduler scheduler = DaemonFactory.INSTANCE.getInstance();
            scheduler.start();

            JobDetail jd = newJob(HeartJob.class).withIdentity("heart", "group1").build();
            Trigger trigger = newTrigger().withIdentity("trigger1", "group1").forJob(jd).withSchedule(simpleSchedule()
                    .withIntervalInSeconds(10)
                    .repeatForever()).build();
            scheduler.scheduleJob(jd, trigger);

            DBBackupTask.INSTANCE.scheduler();

            JobDetail skJD = newJob(SocketJob.class).withIdentity("socketJob").build();
            Trigger skTrigger = newTrigger().withIdentity("socketTrigger").forJob(skJD).build();
            scheduler.scheduleJob(skJD, skTrigger);


            JobDetail eventWJob = newJob(EventJob.class).withIdentity("eventWJob").build();
            Trigger eventWTrigger = newTrigger().withIdentity("eventWTrigger").forJob(eventWJob).withSchedule(simpleSchedule()
                    .withIntervalInHours(24).repeatForever()).build();
            scheduler.scheduleJob(eventWJob, eventWTrigger);

            JobDetail deviceJob = newJob(DeviceStatusDisposeJob.class).withIdentity("deviceStatusJob").build();
            Trigger deviceTrigger = newTrigger().withIdentity("deviceStatusTrigger").withSchedule(CronScheduleBuilder.cronSchedule("0 * 02 * * ?")).forJob(deviceJob).build();
            scheduler.scheduleJob(deviceJob,deviceTrigger);

        } catch (SchedulerException | IOException e) {
            e.printStackTrace();
        }
    }
}
